package org.example.struct.array;

import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.Map;

/**
 * @author liyishan
 * @date 2023/12/26 10:05
 * @apiNote
 */

public class LCR169DismantlingAction {

    public char dismantlingAction(String arr) {
        Map<Character,Integer> map = new LinkedHashMap<>();
        for (char c : arr.toCharArray()) {
            map.put(c,map.getOrDefault(c,0)+1);
        }
        for (Map.Entry<Character,Integer> entry : map.entrySet()) {
            if(entry.getValue() == 1){
                return entry.getKey();
            }
        }
        return ' ';
    }

    public char dismantlingAction1(String arr) {
        HashMap<Character, Boolean> hmap = new HashMap<>();
        char[] sc = arr.toCharArray();
        for(char c : sc) {
            hmap.put(c, !hmap.containsKey(c));
        }
        for(char c : sc) {
            if(hmap.get(c)) {
                return c;
            }
        }
        return ' ';
    }

}
